package com.bawei.mall.user.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bawei.mall.user.domain.MallCusProductCar;
import com.bawei.mall.user.domain.MallProductEntity;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author：HaoYunde
 * @Package：com.bawei.mall.user.mapper
 * @Project：mall_cloud
 * @name：MallCusProductCarMapper
 * @Date：2024/7/5 14:54
 */
public interface MallCusProductCarMapper extends BaseMapper<MallCusProductCar> {

   @Select("\tSELECT\n" +
           "    c.id,\n" +
           "    mpi.id AS productId,\n" +
           "    mpi.img AS productPic,\n" +
           "    mpi.NAME AS productName,\n" +
           "    mpi.product_desc AS productSubTitle,\n" +
           "\t\tmpi.price AS price,\n" +
           "    c.user_id,\n" +
           "    c.create_date,\n" +
           "    c.delete_status,\n" +
           "    c.quantity,\n" +
           "    c.update_date,\n" +
           "    mpsi.id AS productSkuId,\n" +
           "    mpsi.number AS productSkuCode,\n" +
           "    mpsi.sku AS productAttr,\n" +
           "    mpbi.NAME AS productBrand,\n" +
           "    mpavl.product_attribute_id AS productCategoryId \n" +
           "FROM\n" +
           "    mall_cus_product_car c\n" +
           "    INNER JOIN `mall-product`.mall_product_sku_info mpsi ON c.product_sku_id = mpsi.id\n" +
           "    INNER JOIN `mall-product`.mall_product_info mpi ON mpsi.product_id = mpi.id\n" +
           "    INNER JOIN `mall-product`.mall_product_brand_info mpbi ON mpi.brand = mpbi.id\n" +
           "    INNER JOIN `mall-product`.mall_product_attribute_valuelist mpavl ON mpi.id = mpavl.product_id \n" +
           "WHERE\n" +
           "    c.delete_status = 0 and user_id=#{userId}")
    List<MallProductEntity> findListByUserId(Integer userId);


    void deleteAllCar(Integer userId);

    void updateQuantity(@Param("id") Long id, @Param("quantity") Integer quantity);
}
